import java.util.Stack;

public class Solution2 {

        public int evalRPN(String[] tokens) {
            Stack<Integer> stack = new Stack<>();
            //遍历这个字符串，如果是数字字符串，入栈，不是就出栈
            for(int i=0;i<tokens.length;i++){//这是数组，不加括号
                String x=tokens[i];
                if(!iscaculate(x)){//入栈

                    stack.push(Integer.parseInt(x));
                }else{
                    int num1 =stack.pop();
                    int num2 = stack.pop();

                    switch(x){
                        case"+":
                            stack.push(num2+num1);
                            break;

                        case"-":
                            stack.push(num2-num1);
                            break;

                        case"*":
                            stack.push(num2*num1);
                            break;

                        case"/":
                            stack.push(num2/num1);
                            break;
                    }

                }

            }
            return stack.pop();
        }

        private boolean iscaculate(String s){
            if(s.equals("+")||s.equals("-")||s.equals("*")||s.equals("/")){
                return true;
            }return false;



        }
    }

